<?php

namespace Modules\Admin\Http\Controllers;

use App\Admin;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Modules\Admin\Http\Requests\AddAdminUserRequest;

class AdminUserController extends Controller
{
    /**
     *
     * 加载后台用户列表方法
     *
     * Display a listing of the resource.
     * @return Response
     */
    public function index()
    {
        //获取后台所有用户数据
        $admins = Admin::get();
        return view('admin::adminuser.index',compact('admins'));
    }

    /**
     * Store a newly created resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function store(AddAdminUserRequest $request)
    {
        //如果能进入到当前方法内,代表的是填写的数据是通过验证
        //将获取的post数据直接往admins表里面存
        //laravel框架默认是不允许批量存储多个字段的值,所以需要去Admin模型设置一个属性
        //存数据之前应该将密码加密
        $post = $request->all();
        $post['password'] = bcrypt($post['password']);
        Admin::create($post);
        //设置闪存并返回
        session()->flash('success','用户添加成功');
        return redirect()->route('adminuser.index');
    }

    /**
     * Show the specified resource.
     * @return Response
     */
    public function show()
    {
        return view('admin::show');
    }

    /**
     * Show the form for editing the specified resource.
     * @return Response
     */
    public function edit()
    {
        return view('admin::edit');
    }

    /**
     * Update the specified resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function update(Request $request)
    {
    }

    /**
     * Remove the specified resource from storage.
     * @return Response
     */
    public function destroy()
    {
    }
}
